﻿#include "LinkedListQueue.h"
#include<stdexcept>


LinkedListQueue::LinkedListQueue() {
	queueSize = 0;
	head = nullptr;
	rear = nullptr;
}
int LinkedListQueue::getSize() {
	return queueSize;
}
bool LinkedListQueue::isEmpty() {
	return queueSize == 0 ? true : false;
}

//入队
void LinkedListQueue::push(int num) {
	Linkedlist* node = new Linkedlist(num);
	if (head == nullptr) {
		head = node;
		rear = head;	
	}
	else {
		rear->SetNext(num);
		rear = node;
	}
	queueSize++;
}
//出队
int LinkedListQueue::pop() {
	if (queueSize == 0)
		throw std::out_of_range("queue is empty");
	Linkedlist* node = head;
	head = head->GetNext();
	//释放内存
	delete node;
	queueSize--;
	return node->val;
}
//获取队首数据
int LinkedListQueue::getTop() {
	if(queueSize==0)
		throw std::out_of_range("queue is empty");
	return head->val;
}